@use "../../theme";
@use "../../theme-color";
@use "../../shadow";
@use "gtk";
@use "drawing";

/**
 * Base States
 */

.background {
  background-color: theme-color.$surface-z0;
  color: theme-color.$on-surface;
}

dnd {
  color: theme-color.$on-surface;
}

.normal-icons {
  -gtk-icon-size: 16px;
}

.large-icons {
  -gtk-icon-size: 32px;
}

image:disabled {
  -gtk-icon-filter: opacity(0.5);
}

.view {
  // background-color: $surface-z1;
  // color: $on-surface;

  > .cell:hover {
    background-color: theme-color.hover-overlay(theme-color.$on-surface, $alt: true);
  }

  &:disabled {
    color: theme-color.disabled(theme-color.$on-surface);
  }

  &:selected {
    background-color: theme-color.$selected-overlay;
  }

    > .cell:selected:hover {
      background-color: theme-color.hover-overlay(theme-color.$primary, $alt: true, $on: theme-color.$selected-overlay);
    }
}

textview {
  caret-color: theme-color.$primary;

  > text {
    > selection {
      background-color: theme-color.$selected-overlay;
    }
  }

  > border {
    // background-color: $surface-z1-alt;
    color: theme-color.hint(theme-color.$on-surface); // FIXME: not working
  }
}

iconview {
  > .cell {
    border-radius: theme.$corner-radius;
  }

  &:drop(active) {
    // box-shadow: none;
  }

  > dndtarget:drop(active) {
    box-shadow: inset 0 0 0 2px theme-color.$primary;
  }
}

%iconview-desktop {
  // background-color: $scrim;
  color: theme-color.$on-dark;
  text-shadow: shadow.$text-shadow;

  > rubberband {
    border: 1px solid theme-color.primary(theme-color.$on-dark);
    background-color: rgba(theme-color.primary(theme-color.$on-dark), .24);
  }
}

rubberband {
  border: 1px solid theme-color.$primary;
  background-color: rgba(theme-color.$primary, .24);
}

flowbox {
  padding: 4px;
  border-spacing: 4px;

  > flowboxchild {
    padding: 4px;
    border-radius: theme.$corner-radius;

    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);

    &:selected {
      background-color: theme-color.$selected-overlay;

      @include drawing.ink-color(theme-color.$primary, $hover-alt: true, $on: theme-color.$selected-overlay);
    }
  }
}

gridview {
  padding: 4px;
  border-spacing: 4px;

  > child {
    padding: 4px;
    border-radius: theme.$corner-radius;

    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);

    &:selected {
      background-color: theme-color.$selected-overlay;

      @include drawing.ink-color(theme-color.$primary, $hover-alt: true, $on: theme-color.$selected-overlay);
    }
  }
}

coverflow > cover {
  box-shadow: shadow.$z2;
  background-color: theme-color.$surface-z8;
  color: theme-color.$on-surface;
}

.content-view .tile {
  // margin: 2px;
  // padding: 0;
  // border-radius: 0;
  // background-color: black;

  &:selected {
    background-color: transparent;
  }
}

label {
  caret-color: theme-color.$primary;

  &.separator {
    color: theme-color.hint(theme-color.$on-surface);
  }

  &.error {
    color: theme-color.$error;
  }

  > selection {
    background-color: theme-color.$selected-overlay;
  }

  &:disabled {
    color: theme-color.disabled(theme-color.$on-surface);

    headerbar &,
    modelbutton &,
    tab &,
    button & {
      color: inherit;
    }
  }

  &.osd {
    border-radius: theme.$corner-radius;
    background-color: theme-color.$tooltip;
    color: theme-color.$on-tooltip;
  }
}

.dim-label {
  color: theme-color.hint(theme-color.$on-surface);
}

window.assistant {
  .sidebar {
    padding: 4px 0;

    > label {
      min-height: theme.$medium-size;
      padding: 0 12px;
      color: theme-color.disabled(theme-color.$on-surface);
      font-weight: 500;

      &.highlight {
        color: theme-color.$on-surface;
      }
    }
  }
}

window.aboutdialog > box > box > image.large-icons {
  -gtk-icon-size: 128px;
}

%osd,
.osd {
  // opacity: .9;
}

/**
 * Spinner Animation
 */

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

spinner {
  // background: none;
  opacity: 0; // non spinning spinner makes no sense
  color: theme-color.$primary;
  -gtk-icon-source: -gtk-icontheme('process-working-symbolic');
  transition: opacity theme.$state-duration * 4 theme.$ease-out;
  animation: spin 1s linear infinite;

  &:checked {
    opacity: 1;
  }

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }
}

/**
 * General Typography
 */

@function pt($size: $font-size) {
  @return ($size * .75 / 1px) * 1pt;
}

.large-title {
  font-weight: 400;
  font-size: pt(48px);
}

.title-1 {
  font-weight: 400;
  font-size: pt(34px);
  letter-spacing: pt(.25px);
}

.title-2 {
  font-weight: 400;
  font-size: pt(24px);
}

.title-3 {
  font-weight: 500;
  font-size: pt(20px);
  letter-spacing: pt(.15px);
}

.title-4 {
  font-weight: 400;
  font-size: pt(16px);
  letter-spacing: pt(.5px);
}

.heading {
  font-weight: 500;
  font-size: 1em;
}

.body {
  font-weight: 400;
  font-size: 1em;
}

.caption-heading {
  font-weight: 500;
  font-size: pt(12px);
  letter-spacing: pt(1.5px);
}

.caption {
  font-weight: 400;
  font-size: pt(12px);
  letter-spacing: pt(.4px);
}

/**
 * Text Entries
 */

%entry,
entry {
  min-height: theme.$medium-size;
  padding: 0 8px;
  border-spacing: theme.$container-padding;
  border-radius: theme.$corner-radius theme.$corner-radius 0 0;

  @include drawing.entry(normal);

  &:hover,
  &:drop(active) {
    @include drawing.entry(hover);
  }

  &:focus-within {
    @include drawing.entry(checked);

    > text > placeholder {
      opacity: 0;
    }
  }

  &:disabled {
    @include drawing.entry(disabled);
  }

  &.flat {
    min-height: 0;
    padding: 2px;
    border-radius: 0;
    background-color: transparent;
  }

  > text {
    > placeholder {
      color: theme-color.hint(theme-color.$on-surface);
    }

    > selection {
      background-color: theme-color.$selected-overlay;
    }

    > block-cursor {
      background-color: theme-color.$primary;
      color: theme-color.$on-primary;
    }

    > undershoot {
      &.left {
        // @include undershoot(left);
      }

      &.right {
        // @include undershoot(right);
      }
    }
  }

  // icons inside the entry
  > image {
    min-width: theme.$small-size;
    min-height: theme.$small-size;
    border-radius: theme.$circular-radius;
    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface);
    color: theme-color.hint(theme-color.$on-surface);
    margin-top: theme.$container-padding;
    margin-bottom: theme.$container-padding;

    &:disabled {
      color: theme-color.disabled(theme-color.$on-surface);
    }

    &.left {
      margin-left: (theme.$medium-size - theme.$small-size) / 2 - 8px;
    }

    &.right {
      margin-right: (theme.$medium-size - theme.$small-size) / 2 - 8px;
    }
  }

  &.password > image.caps-lock-indicator {
  }

  // entry error and warning style
  @each $class, $color in (".error": theme-color.$error, ".warning": theme-color.$warning) {
    &#{$class} {
      @include drawing.entry(normal, $color);

      &:focus-within {
        @include drawing.entry(checked, $color);
      }

      &:disabled {
        @include drawing.entry(disabled, $color);
      }
    }
  }

  .osd & {
  }

  > progress > trough > progress {
    margin: 0 -8px;
    margin-bottom: -4px;
    border-bottom: 2px solid theme-color.$primary;
    background-color: transparent;
  }

   // linked entries
  .linked:not(.vertical) > & {
    // @extend %linked;
  }

  // Vertically linked entries
  .linked.vertical > & {
    // @extend %linked-vertical;
  }
}

%entry_raised {
  border-radius: theme.$corner-radius;

  @include drawing.entry(raised-normal);

  &:focus-within {
    @include drawing.entry(raised-focus);
  }

  &:drop(active) {
    @include drawing.entry(raised-hover);
  }

  &:disabled {
    @include drawing.entry(raised-disabled);
  }

  // entry error and warning style
  @each $class, $color in (".error": theme-color.$error, ".warning": theme-color.$warning) {
    &#{$class} {
      @include drawing.entry(raised-normal, $color);

      &:focus-within {
        @include drawing.entry(raised-focus, $color);
      }

      &:disabled {
        @include drawing.entry(raised-disabled, $color);
      }

      image {
        color: theme-color.hint(theme-color.on($color));

        &:hover,
        &:active {
          color: theme-color.on($color);
        }

        &:disabled {
          color: theme-color.disabled(theme-color.on($color));
        }
      }
    }
  }
}

treeview entry {
  &,
  &.flat {
    background-color: theme-color.$surface-z1;

    &,
    &:focus-within {
      border-image: none;
      box-shadow: none;
    }
  }
}

.entry-tag {
  margin: 2px;
  border-radius: theme.$circular-radius;
  box-shadow: none;
  background-color: theme-color.fill(theme-color.$on-surface);
  color: theme-color.$on-surface;

  &:hover {
    background-image: image(theme-color.hover-overlay(theme-color.$on-surface));
  }

  // side margins: compensate the entry padding with a negative margin
  // then the negative margin itself
  :dir(ltr) & {
    margin-left: 4px;
    margin-right: 0;
    padding-left: 12px;
    padding-right: 8px;
  }

  :dir(rtl) & {
    margin-left: 0;
    margin-right: 4px;
    padding-left: 8px;
    padding-right: 12px;
  }

  // seems any sizing doesn't work
  &.button {
    box-shadow: none;
    background-color: transparent;
    color: theme-color.hint(theme-color.$on-surface);
  }
}

/**
 * Buttons
 */

// stuff for .needs-attention
@keyframes needs-attention {
  from {
    background-image: radial-gradient(farthest-side, theme-color.$primary 0%, transparent 0%);
  }

  to {
    background-image: radial-gradient(farthest-side, theme-color.$primary 100%, transparent 100%);
  }
}

%button,
button {
  min-height: 24px;
  min-width: 16px;
  padding: (theme.$medium-size - 24px) / 2 (theme.$medium-size - 16px) / 2;
  border-radius: theme.$corner-radius;
  background-color: theme-color.$surface-z8;
  color: theme-color.$on-surface;
  font-weight: 500;

  @extend %ripple;
  @include drawing.ink-color(theme-color.$on-surface, $on: theme-color.$surface-z8, $button-style: "raised");

  &:disabled {
    box-shadow: none;
    background-color: theme-color.fill(theme-color.$on-surface);
    color: theme-color.disabled(theme-color.$on-surface);
  }

  &:checked {
    $background-color: theme-color.activated-overlay(theme-color.$primary, $on: theme-color.$surface-z8);
    color: theme-color.$primary;
    @include drawing.ink-color(theme-color.$primary, $on: $background-color, $button-style: "raised");

    &:disabled {
      box-shadow: none;
      background-color: theme-color.activated-overlay(theme-color.$on-surface, $on: theme-color.fill(theme-color.$on-surface));
      color: theme-color.disabled(theme-color.$on-surface);
    }
  }

  &.text-button {
    min-width: 64px - 16px * 2;
    padding-left: 16px;
    padding-right: 16px;
  }

  &.image-button {
    min-width: 24px;
    padding: (theme.$medium-size - 24px) / 2;
    border-radius: theme.$circular-radius;
  }

  // NOTE: Some image-only buttons use this as well
  &.text-button.image-button {
    min-width: 64px - 16px * 2;
    padding-left: 16px;
    padding-right: 16px;
    // min-width: 24px;
    // padding: ($medium-size - 24px) / 2;
    border-radius: theme.$corner-radius;

    label {
      &:first-child {
        // margin-left: 16px - ($medium-size - 24px) / 2;
      }

      &:last-child {
        // margin-right: 16px - ($medium-size - 24px) / 2;
      }
    }

    image:not(:only-child) {
      // margin: 0 (24px - 16px) / 2;
    }

    image {
      &:first-child {
        margin-left: 12px - 16px;
        margin-right: 8px;
      }

      &:last-child {
        margin-left: 8px;
        margin-right: 12px - 16px;
      }
    }
  }

  .linked:not(.vertical) > & {
    // @extend %linked;

    &.image-button:not(.text-button) {
      // @extend %linked-image-button;
    }
  }

  .linked.vertical > & {
    // @extend %linked-vertical;

    &.image-button:not(.text-button) {
      // @extend %linked-vertical-image-button;
    }
  }
}

%button-outlined {
  background-color: transparent;
  @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true, $button-style: "outlined");
}

%button-flat-basic {
  background-color: transparent;
  color: theme-color.hint(theme-color.$on-surface);
  @include drawing.ink-color(theme-color.$on-surface, $button-style: "flat");

  &:disabled {
    background-color: transparent;
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }
}

%button-flat-activatable {
  @extend %button-flat-basic;

  &:checked {
    $background-color: theme-color.activated-overlay(theme-color.$primary);
    color: theme-color.$primary;
    @include drawing.ink-color(theme-color.$primary, $on: $background-color, $button-style: "flat");

    &:disabled {
      color: theme-color.disabled(theme-color.$on-surface);
    }
  }
}

%button-flat,
button.flat {
  @extend %button-flat-activatable;

  &.text-button {
    min-width: 64px - 8px * 2;
    padding-left: 8px;
    padding-right: 8px;
  }

  &.text-button.image-button {
    min-width: 24px;
    padding: (theme.$medium-size - 24px) / 2;

    label {
      &:first-child {
        margin-left: 12px - (theme.$medium-size - 24px) / 2;
      }

      &:last-child {
        margin-right: 12px - (theme.$medium-size - 24px) / 2;
      }
    }
  }

  .linked:not(.vertical) > &,
  .linked.vertical > & {
    &:not(:only-child) { // specificity bump
      border-radius: theme.$corner-radius;

      &.image-button:not(.text-button) {
        border-radius: theme.$circular-radius;
      }
    }
  }
}

button {
  // big standalone buttons like in Documents pager
  &.osd {
    padding: (theme.$large-size - 24px) / 2 (theme.$large-size - 16px) / 2;

    &.image-button {
      padding: (theme.$large-size - 24px) / 2;
    }

    &:disabled {
      opacity: 0;
    }
  }

  // overlay / OSD style
  @at-root %osd_button,
  .osd & {
  }

  // Suggested and Destructive Action buttons
  @each $class, $color in (".suggested-action": theme-color.$primary, ".destructive-action": theme-color.$error) {
    &#{$class} {
      background-color: $color;
      color: theme-color.on($color);
      @include drawing.ink-color(theme-color.on($color), $on: $color, $button-style: "raised");

      &:disabled {
        box-shadow: none;
        background-color: theme-color.fill(theme-color.$on-surface);
        color: theme-color.disabled(theme-color.$on-surface);
      }

      &:checked {
        background-color: theme-color.activated-overlay(theme-color.on($color), $on: $color);
      }

      &.flat {
        background-color: transparent;
        @include drawing.ink-color($color);

        &:disabled {
          box-shadow: none;
          background-color: transparent;
          color: theme-color.disabled-hint(theme-color.$on-surface);
        }

        &:checked {
          background-color: theme-color.activated-overlay($color);
        }
      }

      .osd & {
      }
    }
  }

  stackswitcher > & {
    // to position the needs attention dot, padding is added to the button
    // child, a label needs just lateral padding while an icon needs vertical
    // padding added too.

    > label {
      margin: 0 -6px;
      padding: 0 6px;
    }

    > image {
      margin: -3px -6px;
      padding: 3px 6px;
    }

    &.needs-attention {
      > label,
      > image {
        @extend %needs-attention;
      }

      &:checked {
        > label,
        > image {
          animation: none;
          background-image: none;
        }
      }
    }
  }

  &.font > box {
    border-spacing: 6px;

    > box {
      > separator {
        @extend %hide_separators;
      }

      > label {
        // font-weight: bold;
      }
    }
  }

  // force circular button shape
  &.close,
  menubutton.circular > &,
  &.circular {
    border-radius: theme.$circular-radius;
  }
}

%button-small {
  min-height: theme.$small-size;
  min-width: theme.$small-size;
  padding: 0;
  border-radius: theme.$circular-radius;
}

%needs-attention {
  animation: needs-attention theme.$ripple-duration theme.$ease-out forwards;
  background-repeat: no-repeat;
  background-position: right 3px;
  background-size: 6px 6px;

  &:dir(rtl) {
    background-position: left 3px;
  }
}

.linked:not(stackswitcher) {
  border-spacing: theme.$container-padding;
}

.linked:not(.vertical) > button.radio {
  border-radius: 0;

  &:first-child {
    border-top-left-radius: theme.$corner-radius;
    border-bottom-left-radius: theme.$corner-radius;
  }

  &:last-child {
    border-top-right-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

  &:not(:first-child) {
    margin-left: -(theme.$container-padding);
  }
}

.linked.vertical > button.radio {
  border-radius: 0;

  &:first-child {
    border-top-left-radius: theme.$corner-radius;
    border-top-right-radius: theme.$corner-radius;
  }

  &:last-child {
    border-bottom-left-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

  &:not(:first-child) {
    margin-top: -(theme.$container-padding);
  }
}

%linked-not-first-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

%linked-not-last-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

%linked {
  &:not(:first-child) {
    @extend %linked-not-first-child;
  }

  &:not(:last-child) {
    @extend %linked-not-last-child;
  }
}

%linked-vertical-not-first-child {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

%linked-vertical-not-last-child {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

%linked-vertical {
  &:not(:first-child) {
    @extend %linked-vertical-not-first-child;
  }

  &:not(:last-child) {
    @extend %linked-vertical-not-last-child;
  }
}

%linked-image-button {
  &:first-child {
    border-top-left-radius: theme.$corner-radius;
    border-bottom-left-radius: theme.$corner-radius;
  }

  &:last-child {
    border-top-right-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

  &:only-child {
    border-radius: theme.$circular-radius;
  }
}

%linked-vertical-image-button {
  &:first-child {
    border-top-left-radius: theme.$corner-radius;
    border-top-right-radius: theme.$corner-radius;
  }

  &:last-child {
    border-bottom-left-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

  &:only-child {
    border-radius: theme.$circular-radius;
  }
}

/* menu buttons */
modelbutton.flat {
  // min-height: $menuitem-size;
  // padding: 0 8px;
  // border-radius: $corner-radius;

  @extend %ripple;
  @include drawing.ink-color(theme-color.$on-surface);

  &:selected {
    // background-color: $selected-overlay;
  }
}

modelbutton.flat arrow {
  min-width: 16px;
  min-height: 16px;
  color: theme-color.hint(theme-color.$on-surface);

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }

  &.left {
    -gtk-icon-source: -gtk-icontheme("pan-start-symbolic");
  }

  &.right {
    -gtk-icon-source: -gtk-icontheme("pan-end-symbolic");
  }
}

button.color {
  min-width: theme.$small-size;
  min-height: theme.$small-size;
  padding: theme.$container-padding;
}

menubutton {
  > button > box > arrow {
    min-height: 16px;
    min-width: 16px;

    &.none {
      -gtk-icon-source: -gtk-icontheme('open-menu-symbolic');
    }

    &.down {
      -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    }

    &.up {
      -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
    }

    &.left {
      -gtk-icon-source: -gtk-icontheme('pan-start-symbolic');
    }

    &.right {
      -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
    }
  }
}

/**
 * Links
 */

link {
  color: theme-color.$primary;

  &:visited {
    color: theme-color.$visited;
  }
}

button.link {
  color: theme-color.$primary;
  @include drawing.ink-color(theme-color.$primary);

  &:visited {
    color: theme-color.$visited;
    @include drawing.ink-color(theme-color.$visited);
  }

  > label {
    text-decoration-line: underline;
  }
}

/**
 * GtkSpinButton
 */

spinbutton {
  font-feature-settings: "tnum";

  &:not(.vertical) {
    // in this horizontal configuration, the whole spinbutton
    // behaves as the entry, so we extend the entry styling
    // and nuke the style on the internal entry
    @extend %entry;

    > text {
      min-width: 32px;
    }

    > button {
      @extend %button-flat-basic;
      @extend %button-small;

      margin: theme.$container-padding 0;

      &.up:dir(ltr),
      &.down:dir(rtl) {
        // margin-left: $container-padding / 2;
      }

      &.up:dir(rtl),
      &.down:dir(ltr) {
        // margin-right: $container-padding / 2;
      }

      &.up:dir(ltr) {
        margin-right: (theme.$medium-size - theme.$small-size) / 2 - 8px;
      }

      &.up:dir(rtl) {
        margin-left: (theme.$medium-size - theme.$small-size) / 2 - 8px;
      }
    }
  }

  // OSD horizontal
  .osd &:not(.vertical) {
  }

  // Vertical
  &.vertical {
    // in the vertical configuration, we treat the spinbutton
    // as a box, and tweak the style of the entry in the middle
    // so that it's linked

    > text {
      @extend %entry_raised;

      min-height: theme.$medium-size;
      min-width: theme.$large-size;
      padding: 0;

      > selection {
        background-color: theme-color.$selected-overlay;
      }
    }

    button {
      min-height: theme.$medium-size;
      min-width: theme.$large-size;
      padding: 0;

      @extend %button-flat-basic;

      // Remove unwanted focus indicator
      &:focus:not(:hover):not(:active) {
        box-shadow: inset 0 0 0 9999px transparent;
      }

      &.up {
        border-radius: theme.$corner-radius theme.$corner-radius 0 0;
      }

      &.down {
        border-radius: 0 0 theme.$corner-radius theme.$corner-radius;
      }
    }
  }

  // OSD vertical
  .osd &.vertical {
  }

  // Misc
  treeview &:not(.vertical) {
    min-height: 0;
    border-style: none;
    border-radius: 0;

    > text {
      min-height: 0;
      padding: 1px 2px;
    }
  }
}

/**
 * ComboBoxes
 */

dropdown,
combobox {
  arrow {
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    transition: -gtk-icon-transform theme.$state-duration theme.$ease-out;
  }

  button:checked arrow {
    color: theme-color.$primary;
    -gtk-icon-transform: rotate(-.5turn);
  }
}

dropdown {
  > button > box {
    border-spacing: 6px;
  }

  > popover.menu > contents {
    // allow search entries with no padding
    padding: 0;

    listview {
      padding: 6px 0;

      > row {
        min-height: 32px - 4px * 2;
        padding: 4px 8px;

        &:selected {
          background-color: theme-color.focus-overlay(theme-color.$on-surface);
        }
      }
    }
  }
}

// drodowns with searchboxes on top
.dropdown-searchbar {
  border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);

  > entry.search {
    border-image: none;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
  }
}

combobox {
  > box > button > box {
    border-spacing: 6px;
  }

  cellview {
    margin: -2px;
  }

  // align menu labels with the button label
  > popover.menu > contents modelbutton {
    padding-left: 8px;
    padding-right: 8px;
  }

  > .linked:not(.vertical) > entry:not(:only-child) {
    // border-radius: $corner-radius $corner-radius 0 0;

    &:first-child {
      margin-right: -(theme.$medium-size + theme.$container-padding);
      padding-right: theme.$medium-size;
    }

    &:last-child {
      margin-left: -(theme.$medium-size + theme.$container-padding);
      padding-left: theme.$medium-size;
    }
  }

  > .linked:not(.vertical) > button:not(:only-child) {
    @extend %button-flat-activatable;
    // @extend %button-small;

    min-height: 16px;
    min-width: 16px;
    margin: (theme.$medium-size - theme.$small-size) / 2;
    padding: (theme.$small-size - 16px) / 2;
    border-radius: theme.$circular-radius;
  }
}

// the combo is a composite widget so the way we do button linking doesn't
// work, special case needed. See
// https://bugzilla.gnome.org/show_bug.cgi?id=733979

.linked:not(.vertical) > combobox {
  &:not(:first-child) > box > button.combo {
    // @extend %linked-not-first-child;
  }

  &:not(:last-child) > box > button.combo {
    // @extend %linked-not-last-child;
  }
}

.linked.vertical > combobox {
  &:not(:first-child) > box > button.combo {
    // @extend %linked-vertical-not-first-child;
  }

  &:not(:last-child) > box > button.combo {
    // @extend %linked-vertical-not-last-child;
  }
}

dropdown > button.toggle,
button.combo:only-child {
  padding-left: 8px;
  padding-right: 8px;
  border-radius: theme.$corner-radius theme.$corner-radius 0 0;
  font-weight: normal;

  @include drawing.entry(normal);

  &:focus {
    @include drawing.entry(focus);
  }

  &:drop(active),
  &:hover {
    @include drawing.entry(hover);
  }

  &:checked {
    @include drawing.entry(checked);
  }

  &:disabled {
    @include drawing.entry(disabled);
  }

  arrow {
    transition: color theme.$state-duration theme.$ease-out;
    color: theme-color.hint(theme-color.$on-surface);

    &:disabled {
      color: theme-color.disabled-hint(theme-color.$on-surface);
    }
  }
}

/**
 * Toolbars
 */

.toolbar {
  padding: 4px;
  border-spacing: 4px;

  &.top { border-bottom: 1px solid theme-color.divider(theme-color.$on-surface); }
  &.bottom { border-top: 1px solid theme-color.divider(theme-color.$on-surface); }
  &.start { border-right: 1px solid theme-color.divider(theme-color.$on-surface); }
  &.end { border-left: 1px solid theme-color.divider(theme-color.$on-surface); }

  button {
    @extend %button-flat;
  }

  // on OSD
  .osd & {
  }

  // stand-alone OSD toolbars
  &.osd {
    @extend %toolbar-osd;

    // positional classes for `attached` osd toolbars
    &.left,
    &.right,
    &.top,
    &.bottom {
      border-radius: 0;
    }

    &.bottom {
      box-shadow: none;
      background-color: transparent;
      background-image:
        linear-gradient(
          to bottom,
          transparent,
          rgba(black, .1) 30%,
          rgba(black, .2) 50%,
          rgba(black, .4)
        );
    }
  }

  // toolbar separators
  &.horizontal > separator {
    margin: 4px 0;
  }

  &.vertical > separator {
    margin: 0 4px;
  }
}

%toolbar-osd {
  transition: theme.$transition-shadow;
  padding: theme.$container-padding;
  border-spacing: theme.$container-padding;
  border-radius: theme.$corner-radius;
  box-shadow: shadow.$z4, inset 0 1px theme-color.highlight(theme-color.$surface-z8);
  background-color: theme-color.$surface-z8;

  &:backdrop {
    box-shadow: shadow.$z2, inset 0 1px theme-color.highlight(theme-color.$surface-z8);
  }
}

// searchbar, location-bar & inline-toolbar
.inline-toolbar {
  padding: theme.$container-padding;
  border-style: solid;
  border-width: 0 1px 1px;
  border-color: theme-color.divider(theme-color.$on-surface);
  background-color: theme-color.$surface-z1;
}

searchbar > revealer > box {
  padding: theme.$container-padding;
  border-spacing: theme.$container-padding;
  border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);
}

/**
 * Title buttons
 */

windowcontrols {
  border-spacing: theme.$container-padding;

  &:not(:only-child):not(.empty) {
    border-image:
      linear-gradient(
        to bottom,
        transparent 12px,
        theme-color.divider(theme-color.$on-titlebar) 12px,
        theme-color.divider(theme-color.$on-titlebar) calc(100% - 12px),
        transparent calc(100% - 12px)
      ) 1;

    &.start:dir(ltr),
    &.end:dir(rtl) {
      padding-right: theme.$container-padding;
      border-right: 1px solid;
    }

    &.start:dir(rtl),
    &.end:dir(ltr) {
      padding-left: theme.$container-padding;
      border-left: 1px solid;
    }
  }

  button {
  }
}

/**
 * Header bars
 */

.titlebar {
  transition: background-color theme.$state-duration theme.$ease-out, color theme.$state-duration theme.$ease-out;
  border-radius: theme.$corner-radius theme.$corner-radius 0 0;
  box-shadow: shadow.$z2, inset 0 1px theme-color.highlight(theme-color.$titlebar);
  background-color: theme-color.$titlebar;
  color: theme-color.$on-titlebar;

  &:disabled {
    color: theme-color.disabled(theme-color.$on-titlebar);
  }

  &:backdrop {
    background-color: theme-color.$titlebar-backdrop;
    color: theme-color.hint(theme-color.$on-titlebar);

    &:disabled {
      color: theme-color.disabled-hint(theme-color.$on-titlebar);
    }
  }

  box.start,
  box.end {
    border-spacing: theme.$container-padding;
  }

  .title {
    padding-left: 12px;
    padding-right: 12px;
    font-weight: bold;
  }

  .subtitle {
    padding-left: 12px;
    padding-right: 12px;
    font-size: smaller;
  }

  .subtitle,
  .dim-label {
    transition: color theme.$state-duration theme.$ease-out;
    color: theme-color.hint(theme-color.$on-titlebar);

    &:backdrop {
      color: theme-color.disabled(theme-color.$on-titlebar);
    }
  }

  // The separator for split headerbars
  headerbar + separator {
    background-color: theme-color.divider(theme-color.$on-titlebar);
  }

  entry {
    box-shadow: inset 0 -1px theme-color.stroke(theme-color.$on-titlebar);
    background-color: theme-color.entry-fill(theme-color.$on-titlebar);
    color: theme-color.$on-titlebar;

    &:disabled {
      box-shadow: inset 0 -1px theme-color.disabled-stroke(theme-color.$on-titlebar);
      background-color: theme-color.entry-fill(theme-color.$on-titlebar);
      color: theme-color.disabled(theme-color.$on-titlebar);
    }

    image {
      color: theme-color.hint(theme-color.$on-titlebar);

      &:hover,
      &:active {
        color: theme-color.$on-titlebar;
      }

      &:disabled {
        color: theme-color.disabled(theme-color.$on-titlebar);
      }
    }
  }

  .linked:not(.vertical) > entry:not(:only-child) {
    border-radius: theme.$corner-radius theme.$corner-radius 0 0;
  }

  @at-root %titlebar-button, & button:not(.suggested-action):not(.destructive-action) {
    @extend %button-flat;

    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  theme-color.$titlebar-indicator 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;
    background-color: transparent;
    color: theme-color.hint(theme-color.$on-titlebar);
    @include drawing.ink-color(theme-color.$on-titlebar);

    &:disabled {
      color: theme-color.disabled-hint(theme-color.$on-titlebar);
    }

    @at-root %titlebar-button-checked,
    &:checked {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    theme-color.$titlebar-indicator 100%,
                                    transparent 100%)
                                    0 0 2 / 0 0 2px;
      background-color: transparent;
      color: theme-color.$on-titlebar;
      @include drawing.ink-color(theme-color.$on-titlebar);

      &:disabled {
        background-color: transparent;
        color: theme-color.disabled(theme-color.$on-titlebar);
      }
    }

    &:backdrop {
      color: theme-color.disabled(theme-color.$on-titlebar);

      &:disabled {
        color: theme-color.disabled-hint(theme-color.$on-titlebar);
      }

      &:checked {
        color: theme-color.hint(theme-color.$on-titlebar);

        &:disabled {
          color: theme-color.disabled-hint(theme-color.$on-titlebar);
        }
      }
    }
  }

  button.suggested-action,
  button.destructive-action {
    &:disabled {
      background-color: theme-color.fill(theme-color.$on-titlebar);
      color: theme-color.disabled(theme-color.$on-titlebar);
    }
  }

  // FIXME: Ugly overriding
  stackswitcher button:not(.suggested-action):not(.destructive-action).text-button {
    min-width: 120px - 8px * 2;
  }

  // FIXME: Ugly overriding
  .path-bar button:not(.suggested-action):not(.destructive-action).text-button {
    min-width: 0;
    padding-left: (theme.$medium-size - 24px) / 2;
    padding-right: (theme.$medium-size - 24px) / 2;
  }

  &.selection-mode {
    // 0.1ms was a workaround for https://gitlab.gnome.org/GNOME/gtk/issues/698
    // but let's keep it for backwards compatibility.
    transition: background-color 0.1ms theme.$ripple-duration, color theme.$state-duration theme.$ease-out;
    animation: ripple-on-headerbar theme.$ripple-duration theme.$ease-out;
    box-shadow: shadow.$z2, inset 0 1px theme-color.highlight(theme-color.$primary);
    background-color: theme-color.$primary;
    color: theme-color.$on-primary;

    &:backdrop {
      color: theme-color.hint(theme-color.$on-primary);
    }

    .subtitle:link {
      color: theme-color.$on-primary;
    }

    button:not(.suggested-action):not(.destructive-action) {
      border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                    currentColor 0%,
                                    transparent 0%)
                                    0 0 0 / 0 0 0px;
      color: theme-color.$on-primary;

      &:disabled {
        color: theme-color.disabled(theme-color.$on-primary);
      }

      &:checked {
        border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                      currentColor 100%,
                                      transparent 100%)
                                      0 0 2 / 0 0 2px;
        color: theme-color.$on-primary;

        &:disabled {
          color: theme-color.disabled(theme-color.$on-primary);
        }
      }

      &:backdrop {
        color: theme-color.hint(theme-color.$on-primary);

        &:disabled {
          color: theme-color.disabled-hint(theme-color.$on-primary);
        }

        &:checked {
          color: theme-color.hint(theme-color.$on-primary);

          &:disabled {
            color: theme-color.disabled-hint(theme-color.$on-primary);
          }
        }
      }
    }

    .selection-menu {
      padding-left: 16px;
      padding-right: 16px;

      .arrow {
        -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
      }
    }
  }

  .selection-mode {
    box-shadow: inset 0 1px theme-color.highlight(theme-color.$primary); // Avoid double shadows
    background-color: theme-color.$primary;
  }

  // squared corners when the window is maximized, tiled, or fullscreen
  .tiled &,
  .tiled-top &,
  .tiled-right &,
  .tiled-bottom &,
  .tiled-left &,
  .maximized &,
  .fullscreen & {
    border-radius: 0;
    box-shadow: shadow.$z2;
  }

  &.default-decoration {
    min-height: theme.$small-size;
    padding: theme.$container-padding;
    box-shadow: inset 0 1px theme-color.highlight(theme-color.$titlebar);

    .tiled &,
    .maximized &,
    .fullscreen & {
      box-shadow: none;
    }

    button.titlebutton {
      min-height: theme.$small-size;
      min-width: theme.$small-size;
      margin: 0;
      padding: 0;
    }

    // workaround for non-animatable buttons
    .background:not(.csd) & button.titlebutton:active {
      background-size: 1000% 1000%;
    }
  }

  .solid-csd & {
    &:dir(rtl), &:dir(ltr) { // specificity bump
      border-radius: 0;
      box-shadow: shadow.$z2; // just remove the highlight
    }
  }
}

headerbar > windowhandle > box {
  // The sizing factor needs to be defined in the headerbar node for the case of split headerbars
  min-height: theme.$large-size;
  padding: 0 theme.$container-padding;
  border-spacing: theme.$container-padding;

  // add vertical margins to common widget on the headerbar to avoid them spanning the whole height
  entry,
  spinbutton,
  button {
    margin-top: theme.$container-padding;
    margin-bottom: theme.$container-padding;
  }

  separator.titlebutton {
    margin-top: theme.$large-size / 4;
    margin-bottom: theme.$large-size / 4;
    background-color: theme-color.divider(theme-color.$on-titlebar);
  }

  switch {
    margin-top: (theme.$large-size - 24px) / 2;
    margin-bottom: (theme.$large-size - 24px) / 2;
  }

  // reset button margins of the spinbutton
  spinbutton button {
    margin-top: 0;
    margin-bottom: 0;
  }

  // FIXME: This is a hacky workaround.
  .entry-tag {
    margin-top: 5px;
    margin-bottom: 5px;
  }
}

// Development versions of apps to use a differently styled headerbar
window.devel .titlebar:not(.selection-mode) {
}

/**
 * Pathbars
 */

%pathbar_button,
pathbar.linked:not(.vertical) > button {
  @extend %button-flat-basic;

  padding-left: (theme.$medium-size - 24px) / 2;
  padding-right: (theme.$medium-size - 24px) / 2;
  border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                theme-color.$primary 0%,
                                transparent 0%)
                                0 0 0 / 0 0 0px;
  border-radius: theme.$corner-radius;

  &:checked {
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  theme-color.$primary 100%,
                                  transparent 100%)
                                  0 0 2 / 0 0 2px;
    color: theme-color.$on-surface;

    &,
    &:disabled {
      background-color: transparent;
    }
  }

  label:not(:only-child) {
    &:first-child {
      margin-left: 0;
    }

    &:last-child {
      margin-right: 0;
    }
  }

  &.text-button {
    min-width: 0;
  }

  &.slider-button {
    padding-left: (24px - 16px) / 2;
    padding-right: (24px - 16px) / 2;
  }
}

/**
 * Tree Views
 */

columnview.view,
treeview.view {
  border-left-color: theme-color.stroke(theme-color.$on-surface); // this is actually the tree lines color,
  border-top-color: theme-color.divider(theme-color.$on-surface); // while this is the grid lines color, better then nothing

  // to avoid borders being overridden by the previously set props
  > rubberband {
    @extend rubberband;
  }

  // FIXME: Avoid transparency background-color being slightly darker
  &:selected {
    // background-color: $surface-z1;
    // background-image: image($selected-overlay);
  }

  &:hover,
  &:selected {
    // border-radius: 0;
  }

  &.separator {
    min-height: 1px + 2px * 2;
    color: theme-color.divider(theme-color.$on-surface);
  }

  &:drop(active) {
    box-shadow: none;
  }

  > dndtarget:drop(active) {
    // FIXME: box-shadow, background-color and background-image are not available here.
    border-style: solid none;
    border-width: 9999px;
    border-color: theme-color.hover-overlay(theme-color.$on-surface);

    &.after {
      border-top-style: none;
    }

    &.before {
      border-bottom-style: none;
    }
  }

  &.expander {
    // GtkTreeView uses the larger of the expander’s min-width and min-height
    min-width: 16px;
    min-height: 16px;
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    -gtk-icon-transform: rotate(-90deg);

    &:dir(rtl) {
      -gtk-icon-transform: rotate(90deg);
    }

    &:checked {
      -gtk-icon-transform: unset;
    }

    color: theme-color.hint(theme-color.$on-surface);

    &:hover,
    &:active {
      color: theme-color.$on-surface;
    }

    &:disabled {
      color: theme-color.disabled-hint(theme-color.$on-surface);
    }
  }

  &.progressbar { // progress bar in treeviews
    border-bottom: 4px solid theme-color.$primary;
    background-color: transparent;

    &:selected:hover {
      background-color: transparent;
    }
  }

  &.trough { // progress bar trough in treeviews
    border-bottom: 4px solid theme-color.disabled-stroke(theme-color.$on-surface);
    background-color: transparent;

    &:selected:hover {
      background-color: transparent;
    }
  }

  > header {
    > button {
      padding: 2px 6px;
      border-style: none solid solid none;
      border-width: 1px;
      border-color: theme-color.divider(theme-color.$on-surface);
      border-radius: 0;
      background-clip: padding-box;
      background-color: transparent;
      color: theme-color.hint(theme-color.$on-surface);
      @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true, $button-style: "flat");
      @include drawing.list-item;

      &:disabled {
        color: theme-color.disabled-hint(theme-color.$on-surface);
      }

      &,
      &:disabled {
        // background-color: $surface-z1;
      }

      &:last-child {
        border-right-style: none;
      }

      > box > sort-indicator {
        min-height: 16px;
        min-width: 16px;

        &.ascending {
          -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
        }

        &.descending {
          -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
        }
      }
    }
  }

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    padding: 2px 6px;
    border-style: none solid solid;
    border-width: 1px;
    border-color: theme-color.divider(theme-color.$on-surface);
    border-radius: 0;
    box-shadow: none;
    // background-color: $surface-z1;
    background-clip: border-box;
    color: theme-color.$primary;
  }

  // see tests/testaccel to test
  acceleditor > label {
    background-color: theme-color.$primary;
  }
}

/**
 * Menus
 */

menubar {
  // box-shadow: inset 0 -1px divider($on-surface);
  background-color: theme-color.$titlebar;
  color: theme-color.$on-titlebar;

  &:backdrop {
    background-color: theme-color.$titlebar-backdrop;
    color: theme-color.hint(theme-color.$on-titlebar);
  }

  .csd & {
    transition: theme.$transition;
  }

  > item {
    // transition: $transition;
    min-height: 20px;
    padding: 4px 8px;
    color: theme-color.hint(theme-color.$on-titlebar);

    @extend %ripple;
    // @include ink-color($on-titlebar);

    &:hover {
      background-color: theme-color.hover-overlay(theme-color.$on-titlebar);
    }

    &:focus:not(:hover) {
      background-color: theme-color.focus-overlay(theme-color.$on-titlebar);
    }

    &:active {
      background-image: radial-gradient(circle, theme-color.pressed-overlay(theme-color.$on-titlebar) 10%, transparent 10%);
    }

    &:selected:not(:focus) {
      transition: none;
      background-color: theme-color.activated-overlay(theme-color.$on-titlebar);
      color: theme-color.$on-titlebar;
    }

    &:disabled {
      color: theme-color.disabled-hint(theme-color.$on-titlebar);
    }
  }
}

popover.menu {
  > contents {
    padding: 6px 0;
  }

  separator {
    margin: 6px 0;
  }

  label.title {
    min-height: 32px - 4px * 2;
    padding: 4px 32px; // this will fall apart with font sizing
    font-weight: bold;
  }

  modelbutton {
    // transition: background-color $state-duration $ease-out;
    min-height: 30px - 4px * 2;
    min-width: 40px;
    padding: 4px 32px;

    &:hover {
      // transition: none;
      // background-color: hover-overlay($on-surface);
    }

    &:disabled {
      color: theme-color.disabled(theme-color.$on-surface);
    }

    accelerator {
      color: theme-color.hint(theme-color.$on-surface);

      &:dir(ltr) {
        margin-left: 24px;
        margin-right: 16px - 32px;
      }

      &:dir(rtl) {
        margin-left: 16px - 32px;
        margin-right: 24px;
      }
    }

    &:disabled accelerator {
      color: theme-color.disabled-hint(theme-color.$on-surface);
    }
  }

  check,
  radio {
    &,
    &:focus,
    &:hover,
    &:active,
    &:disabled {
      // transition: none;
      background-color: transparent;
      background-image: none;
    }
  }

  arrow,
  check,
  radio {
    min-width: 16px;
    min-height: 16px;
    margin: 0;
    padding: 0;

    &.left {
      margin-left: 8px - 32px;
      margin-right: 8px;
    }

    &.right {
      margin-left: 8px;
      margin-right: 8px - 32px;
    }
  }

  button.model {
    @extend %button-flat;

    // min-height: 32px;
    // padding: 0 8px;
    // border-radius: $corner-radius;

    &:checked {
      // color: $primary;
    }
  }

  box.inline-buttons {
    padding: 0 8px;

    button.image-button.model {
    }
  }

  box.circular-buttons {
    padding: 4px 32px;

    button.circular.image-button.model {
      padding: 12px;
    }
  }
}

/**
 * Popovers
 */

popover {
  font: initial; // Decouple the font of popovers from their entry/textview

  &.background {
    background-color: transparent;
  }

  > arrow,
  > contents {
    transition: theme.$transition-shadow;
    box-shadow: shadow.$z4;
    background-color: theme-color.$surface-z8;
    color: theme-color.$on-surface;

    &:backdrop {
      box-shadow: shadow.$z2;
    }
  }

  @at-root %popover-border {
    border-width: 1px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.3);
    background-clip: padding-box;
  }

  > arrow {
    @extend %popover-border;
  }

  > contents {
    padding: 8px;

    @if gtk.$version >= 4.2 {
      border-radius: theme.$corner-radius;
    } @else {
      @extend %popover-border;
      border-radius: theme.$corner-radius + 1px;
    }

    > list,
    .view,
    > .toolbar {
      border-style: none;
      box-shadow: none;
      background-color: transparent;
    }

    separator {
      // margin: 4px 0;
    }

    list separator {
      // margin: 0;
    }
  }

  .osd &,
  &.touch-selection,
  &.magnifier {
    // @extend %osd;
  }

  button {
    @extend %button-outlined;
  }

  frame,
  .frame {
    border: 1px solid theme-color.divider(theme-color.$on-surface);
    box-shadow: none;
    background-color: transparent;
  }

  .linked:not(.vertical) > entry:not(:only-child) {
    // border-radius: $corner-radius $corner-radius 0 0;
  }
}

/**
 * Notebooks
 */

notebook {
  &:focus:focus-visible > header > tabs > tab:checked {
    background-color: theme-color.focus-overlay(theme-color.$primary);
  }

  > header {
    &.top {
      box-shadow: inset 0 -1px theme-color.divider(theme-color.$on-surface);

      > tabs {
        > tab {
          box-shadow: inset 0 -2px transparent;

          &:checked {
            box-shadow: inset 0 -2px theme-color.$primary;
          }
        }
      }
    }

    &.bottom {
      box-shadow: inset 0 1px theme-color.divider(theme-color.$on-surface);

      > tabs {
        > tab {
          box-shadow: inset 0 2px transparent;

          &:checked {
            box-shadow: inset 0 2px theme-color.$primary;
          }
        }
      }
    }

    &.left {
      box-shadow: inset -1px 0 theme-color.divider(theme-color.$on-surface);

      > tabs {
        > tab {
          box-shadow: inset -2px 0 transparent;

          &:checked {
            box-shadow: inset -2px 0 theme-color.$primary;
          }
        }
      }
    }

    &.right {
      box-shadow: inset 1px 0 theme-color.divider(theme-color.$on-surface);

      > tabs {
        > tab {
          box-shadow: inset 2px 0 transparent;

          &:checked {
            box-shadow: inset 2px 0 theme-color.$primary;
          }
        }
      }
    }

    &.top > tabs > arrow {
      @extend %notebook_vert_arrows;
    }

    &.bottom > tabs > arrow {
      @extend %notebook_vert_arrows;
    }

    @at-root %notebook_vert_arrows {
      &.down {
        -gtk-icon-source: -gtk-icontheme('pan-start-symbolic');
      }

      &.up {
        -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
      }
    }

    &.left > tabs > arrow {
      @extend %notebook_horz_arrows;
    }

    &.right > tabs > arrow {
      @extend %notebook_horz_arrows;
    }

    @at-root %notebook_horz_arrows {
      &.down {
        -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
      }

      &.up {
        -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
      }
    }

    > tabs > arrow {
      min-height: 16px;
      min-width: 16px;
      padding: 4px;
      border-radius: 0;
      color: theme-color.hint(theme-color.$on-surface);
      @extend %ripple;
      @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);

      &:disabled {
        color: theme-color.disabled-hint(theme-color.$on-surface);
      }
    }

    > tabs > tab {
      @extend %ripple;
      @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);
      min-height: theme.$small-size;
      min-width: theme.$small-size;
      padding: theme.$container-padding 12px;
      color: theme-color.hint(theme-color.$on-surface);
      font-weight: 500;

      &:hover {
        // background-color: hover-overlay($on-surface, $alt: true);
      }

      &:active {
        // background-image: radial-gradient(circle, pressed-overlay($on-surface) 10%, transparent 10%);
      }

      &:disabled {
        color: theme-color.disabled-hint(theme-color.$on-surface);
      }

      &:checked {
        @include drawing.ink-color(theme-color.$primary, $hover-alt: true);
        color: theme-color.$primary;

        &:hover {
          // background-color: hover-overlay($primary, $alt: true);
        }

        &:active {
          // background-image: radial-gradient(circle, pressed-overlay($primary) 10%, transparent 10%);
        }

        &:disabled {
          color: theme-color.disabled-hint(theme-color.$on-surface);
        }

        &.reorderable-page {
          // border-color: divider($on-surface);
          // background-color: $surface-z1;
        }
      }

      // FIXME: The tab node doesn't have :drop(active), instead its child box has it.
      > box {
        transition: background-color theme.$state-duration theme.$ease-out;
        margin: -(theme.$container-padding) -12px;
        padding: theme.$container-padding 12px;

        &:drop(active) {
          background-color: theme-color.hover-overlay(theme-color.$on-surface);
        }
      }

      // colors the button like the label, overridden otherwise
      button.flat {
        @extend %button-small;

        &:last-child {
          margin-left: theme.$container-padding;
          margin-right: theme.$container-padding - 12px;
        }

        &:first-child {
          margin-left: theme.$container-padding - 12px;
          margin-right: theme.$container-padding;
        }
      }
    }
  }
}

/**
 * Scrollbars
 */

scrollbar {
  $_slider_min_length: 24px;

  transition: theme.$transition;
  background-clip: padding-box;
  // background-color: $surface-z1;

  // scrollbar border
  &.top { border-bottom: 1px solid theme-color.divider(theme-color.$on-surface); }
  &.bottom { border-top: 1px solid theme-color.divider(theme-color.$on-surface); }
  &.left { border-right: 1px solid theme-color.divider(theme-color.$on-surface); }
  &.right { border-left: 1px solid theme-color.divider(theme-color.$on-surface); }

  // slider
  > range > trough > slider {
    transition: background-color theme.$state-duration theme.$ease-out;
    min-width: 10px;
    min-height: 10px;
    border: 3px solid transparent;
    border-radius: theme.$circular-radius;
    background-clip: padding-box;
    background-color: theme-color.scrollbar-thumb(theme-color.$on-surface);

    &:hover {
      background-color: theme-color.scrollbar-thumb(theme-color.$on-surface, "hover");
    }

    &:active {
      background-color: theme-color.scrollbar-thumb(theme-color.$on-surface, "pressed");
    }

    &:disabled {
      background-color: theme-color.scrollbar-thumb(theme-color.$on-surface, "disabled");
    }
  }

  &.horizontal > range > trough > slider {
    min-width: $_slider_min_length;
  }

  &.vertical > range > trough > slider {
    min-height: $_slider_min_length;
  }

  > range.fine-tune {
    > trough > slider {
      min-width: 4px;
      min-height: 4px;
    }

    &.horizontal > trough > slider {
      margin: 3px 0;
    }

    &.vertical > trough > slider {
      margin: 0 3px;
    }
  }

  &.overlay-indicator {
    > range:not(.fine-tune) > trough > slider {
      transition-property: background-color, min-height, min-width;
    }

    &:not(.dragging):not(.hovering) {
      border-color: transparent;
      background-color: transparent;

      > range > trough > slider {
        min-width: 4px;
        min-height: 4px;
        margin: 3px - 1px;
        border: 1px solid rgba(theme-color.$surface-z1, 0.3);
      }

      &.horizontal > range > trough > slider {
        min-width: $_slider_min_length;
      }

      &.vertical > range > trough > slider {
        min-height: $_slider_min_length;
      }
    }

    &.dragging,
    &.hovering {
      background-color: theme-color.$surface-z8;
    }
  }
}

/**
 * Switch
 */

switch {
  transition: all theme.$state-duration theme.$ease-out;
  margin: theme.$container-padding 0;
  padding: 0 2px;
  border: 5px solid transparent;
  border-radius: theme.$circular-radius;
  background-color: theme-color.stroke(theme-color.$on-surface);
  background-clip: padding-box;
  font-size: 0;

  &:checked {
    background-color: rgba(theme-color.$primary, .5);
  }

  &:disabled {
    opacity: .5;
  }

  // hide on/off icons for >=3.24.5
  > image {
    margin: -8px;
    -gtk-icon-transform: scale(0);
  }

  > slider {
    transition: all theme.$state-duration theme.$ease-out;
    min-width: 20px;
    min-height: 20px;
    margin: -3px -2px;
    border-radius: theme.$circular-radius;
    box-shadow:
      0 0 0 10px transparent,
      0 0 0 -10px theme-color.pressed-overlay(theme-color.$on-surface),
      shadow.$z1;
    background-color: theme-color.$surface-switch-thumb;
  }

  &:hover > slider {
    box-shadow:
      0 0 0 10px theme-color.hover-overlay(theme-color.$on-surface),
      0 0 0 -10px theme-color.pressed-overlay(theme-color.$on-surface),
      shadow.$z1;
  }

  &:focus > slider {
    box-shadow:
      0 0 0 10px theme-color.focus-overlay(theme-color.$on-surface),
      0 0 0 -10px theme-color.pressed-overlay(theme-color.$on-surface),
      shadow.$z1;
  }

  &:active > slider {
    box-shadow:
      0 0 0 10px theme-color.hover-overlay(theme-color.$on-surface),
      0 0 0 10px theme-color.pressed-overlay(theme-color.$on-surface),
      shadow.$z1;
  }

  &:checked > slider {
    background-color: theme-color.$primary;
  }

  &:checked:hover > slider {
    box-shadow:
      0 0 0 10px theme-color.hover-overlay(theme-color.$primary),
      0 0 0 -10px theme-color.pressed-overlay(theme-color.$primary),
      shadow.$z1;
  }

  &:checked:focus > slider {
    box-shadow:
      0 0 0 10px theme-color.focus-overlay(theme-color.$primary),
      0 0 0 -10px theme-color.pressed-overlay(theme-color.$primary),
      shadow.$z1;
  }

  &:checked:active > slider {
    box-shadow:
      0 0 0 10px theme-color.hover-overlay(theme-color.$primary),
      0 0 0 10px theme-color.pressed-overlay(theme-color.$primary),
      shadow.$z1;
  }

  row:selected & {
  }
}

/**
 * Check and Radio items
 */

// draw regular check and radio items using our PNG assets
// all assets are rendered from assets.svg. never add pngs directly

// selection-mode
.view.content-view.check:not(list),
.content-view:not(list) .tile check {
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 0;
  background-color: transparent;
  background-image: none;
  -gtk-icon-shadow: shadow.$icon-shadow-z2;

  &:hover,
  &:active {
    -gtk-icon-shadow: shadow.$icon-shadow-z4;
  }

  @each $class, $suffix in ("": "-unchecked", ":checked": "-checked") {
    &#{$class} {
      $_url: 'assets/selectionmode-checkbox#{$suffix}#{theme.$asset-suffix}';

      -gtk-icon-source: -gtk-scaled(url("#{$_url}.png"), url("#{$_url}@2.png"));
    }
  }
}

checkbutton,
radiobutton {
  border-spacing: 4px;

  &.text-button {
    padding: 4px;
  }
}

$check-radio-size: 40px;

check,
radio {
  min-height: 24px;
  min-width: 24px;
  margin: -($check-radio-size - 24px) / 2;
  padding: ($check-radio-size - 24px) / 2;
  border-radius: theme.$circular-radius;
  color: theme-color.hint(theme-color.$on-surface);
  @extend %ripple;
  @include drawing.ink-color(theme-color.$on-surface);

  &:checked,
  &:indeterminate {
    color: theme-color.$primary;
    @include drawing.ink-color(theme-color.$primary);
  }

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }
}

%check,
check {
  -gtk-icon-source: -gtk-recolor(url("icons/checkbox-unchecked-symbolic.svg"));

  &:checked {
    -gtk-icon-source: -gtk-recolor(url("icons/checkbox-checked-symbolic.svg"));
  }

  &:indeterminate {
    -gtk-icon-source: -gtk-recolor(url("icons/checkbox-mixed-symbolic.svg"));
  }
}

%radio,
radio {
  -gtk-icon-source: -gtk-recolor(url("icons/radio-unchecked-symbolic.svg"));

  &:checked {
    // -gtk-icon-source: -gtk-recolor(url("icons/radio-checked-symbolic.svg"));
  }

  &:indeterminate {
    -gtk-icon-source: -gtk-recolor(url("icons/radio-mixed-symbolic.svg"));
  }

  border-image-slice: $check-radio-size / 2px;
  border-image-width: $check-radio-size / 2;

  $radio-indicator-size: 10px / $check-radio-size / 2;

  border-image-source: radial-gradient(circle, theme-color.$primary 0%, transparent 0%);

  &:checked:not(:indeterminate) {
    border-image-source: radial-gradient(circle, theme-color.$primary 4.5px, transparent 5px);

    &:disabled {
      border-image-source: radial-gradient(circle, theme-color.disabled-hint(theme-color.$on-surface) 4.5px, transparent 5px);
    }
  }
}

%small_check,
popover.menu modelbutton check {
  min-height: 16px;
  min-width: 16px;
  border-radius: theme.$corner-radius;
  -gtk-icon-source: -gtk-recolor(url("icons/small-checkbox-unchecked-symbolic.svg"));

  &:checked {
    -gtk-icon-source: -gtk-recolor(url("icons/small-checkbox-checked-symbolic.svg"));
  }

  &:indeterminate {
    -gtk-icon-source: -gtk-recolor(url("icons/small-checkbox-mixed-symbolic.svg"));
  }
}

%small_radio,
popover.menu modelbutton radio {
  min-height: 16px;
  min-width: 16px;
  border-image: none;
  -gtk-icon-source: -gtk-recolor(url("icons/small-radio-unchecked-symbolic.svg"));

  &:checked {
    -gtk-icon-source: -gtk-recolor(url("icons/small-radio-checked-symbolic.svg"));
  }

  &:indeterminate {
    -gtk-icon-source: -gtk-recolor(url("icons/small-radio-mixed-symbolic.svg"));
  }
}

// ANIMATION:
// this is made with those pretty convoluted transitions, since checks and radios have to animate only on state changes,
// the transformation is set on the active state and it get reset on the checked state.
radio:not(:checked):active {
  // -gtk-icon-transform: scale(0);
}

// Otherwise, treeview.view styling will be applied...
treeview.view check,
treeview.view radio {
  padding: 0;
  color: theme-color.hint(theme-color.$on-surface);

  &:checked,
  &:indeterminate {
    color: theme-color.$primary;
  }

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }

  &,
  &:hover,
  &:selected,
  &:selected:hover {
    background-color: transparent;
  }
}

treeview.view radio:checked {
  -gtk-icon-source: -gtk-recolor(url("icons/radio-checked-symbolic.svg"));
  border-image: none;
}

/**
 * GtkScale
 */

scale {
  // sizing
  $_marks_length: 8px;
  $_marks_distance: 7px;

  $trough_size: 2px;
  $finetune_trough_size: 4px;

  $slider_size: 32px;

  $slider_margin: -($slider_size - $trough_size) / 2;
  $finetune_slider_margin: -($slider_size - $finetune_trough_size) / 2;

  $color_slider_margin: -($slider_size) * 3 / 4;
  $color_marks_slider_margin: -($slider_size - 16px) - $color_slider_margin;

  min-height: $trough_size;
  min-width: $trough_size;

  &.horizontal {
    padding: (theme.$medium-size - $trough_size) / 2 12px;
  }

  &.vertical {
    padding: 12px (theme.$medium-size - $trough_size) / 2;
  }

  // click-and-hold the slider to activate
  &.fine-tune {
    &.horizontal {
      min-height: $finetune_trough_size;
      padding-top: (theme.$medium-size - $finetune_trough_size) / 2;
      padding-bottom: (theme.$medium-size - $finetune_trough_size) / 2;
    }

    &.vertical {
      min-width: $finetune_trough_size;
      padding-left: (theme.$medium-size - $finetune_trough_size) / 2;
      padding-right: (theme.$medium-size - $finetune_trough_size) / 2;
    }

    // to make the trough grow in fine-tune mode
    > trough > slider {
      margin: $finetune_slider_margin;
    }
  }

  // the backing bit
  > trough {
    transition: background-color theme.$state-duration theme.$ease-out;
    background-color: theme-color.stroke(theme-color.$on-surface);

    &:disabled {
      background-color: theme-color.disabled-stroke(theme-color.$on-surface);
    }

    // the colored part of the backing bit
    > highlight {
      transition: background-image theme.$state-duration theme.$ease-out;
      background-image: image(theme-color.$primary);

      &:disabled {
        background-color: theme-color.$surface-z0;
        background-image: image(theme-color.disabled-hint(theme-color.$on-surface));
      }
    }

    // this is another differently styled part of the backing bit, the most relevant use case is for example
    // in media player to indicate how much video stream as been cached
    > fill {
      transition: background-color theme.$state-duration theme.$ease-out;
      background-color: theme-color.stroke(theme-color.$on-surface);

      &:disabled {
        background-color: transparent;
      }
    }

    > slider {
      transition: background-color theme.$state-duration theme.$ease-out,
                  background-size theme.$ripple-fade-out-duration theme.$ease-out,
                  background-image theme.$ripple-opacity-fade-out-duration theme.$ease-out;
      min-width: $slider_size;
      min-height: $slider_size;
      // the slider is inside the trough, so to have make it bigger there's a negative margin
      margin: $slider_margin;
      border-radius: 50%;
      background-repeat: no-repeat;
      background-position: center;
      background-size: auto, 1000% 1000%;
      color: theme-color.$primary;

      @each $class, $suffix in ("": "", ":disabled": "-disabled") {
        &#{$class} {
          $_url: 'assets/scale-slider#{$suffix}#{theme.$asset-suffix}';

          background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png')),
                            radial-gradient(circle, transparent 10%, transparent 10%);
        }
      }

      &:hover {
        background-color: theme-color.hover-overlay(theme-color.$primary);
      }

      &:focus {
        background-color: theme-color.focus-overlay(theme-color.$primary);
      }

      &:active {
        $_url: 'assets/scale-slider#{theme.$asset-suffix}';

        transition: background-color theme.$state-duration theme.$ease-out,
                    background-size 0ms,
                    background-image 0ms;
        animation: ripple-on-slider theme.$ripple-duration theme.$ease-out forwards;
        background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png')),
                          radial-gradient(circle, theme-color.pressed-overlay(theme-color.$primary) 10%, transparent 10%);
        background-size: auto, 0% 0%;
      }
    }
  }

  > marks,
  > value {
    color: theme-color.hint(theme-color.$on-surface);
  }

  > value {
    font-feature-settings: "tnum";
  }

  indicator {
    background-color: theme-color.stroke(theme-color.$on-surface);
  }

  //marks margins
  @each $scale_orient, $marks_class, $marks_pos, $marks_margin in (horizontal, top, top, bottom),
                                                                  (horizontal, bottom, bottom, top),
                                                                  (vertical, top, left, right),
                                                                  (vertical, bottom, right, left) {
    &.#{$scale_orient} > marks {
      &.#{$marks_class} {
        margin-#{$marks_margin}: $_marks_distance;
        margin-#{$marks_pos}: -($_marks_distance + $_marks_length);
      }
    }

    &.#{$scale_orient}.fine-tune > marks {
      &.#{$marks_class} {
        margin-#{$marks_margin}: $_marks_distance - 1px;
        margin-#{$marks_pos}: -($_marks_distance + $_marks_length - 1px);
      }
    }
  }

  &.horizontal {
    indicator {
      min-height: $_marks_length;
      min-width: 1px;
    }
  }

  &.vertical {
    indicator {
      min-height: 1px;
      min-width: $_marks_length;
    }
  }

  // *WARNING* scale with marks madness following

  @each $dir_class, $dir_infix in (".horizontal": "-horz", ".vertical": "-vert") {
    @each $marks_class, $marks_infix in (
      ".marks-before:not(.marks-after)": "-marks-before",
      ".marks-after:not(.marks-before)": "-marks-after"
    ) {
      &#{$dir_class}#{$marks_class} > trough > slider {
        @each $state_class, $state_infix in ("": "", ":disabled": "-disabled") {
          &#{$state_class} {
            $_scale_asset: 'assets/scale#{$dir_infix}#{$marks_infix}-slider#{$state_infix}#{theme.$asset-suffix}';

            background-image:
              -gtk-scaled(url('#{$_scale_asset}.png'), url('#{$_scale_asset}@2.png')),
              radial-gradient(circle, transparent 10%, transparent 10%);
          }
        }

        &:active {
          $_scale_asset: 'assets/scale#{$dir_infix}#{$marks_infix}-slider#{theme.$asset-suffix}';

          background-image:
            -gtk-scaled(url('#{$_scale_asset}.png'), url('#{$_scale_asset}@2.png')),
            radial-gradient(circle, theme-color.pressed-overlay(theme-color.$primary) 10%, transparent 10%);
        }
      }
    }
  }

  &.color {
    min-height: 0;
    min-width: 0;

    &.horizontal {
      // specificity bump
      &:dir(ltr),
      &:dir(rtl) {
        padding: 0 0 12px 0;

        slider {
          margin-bottom: $color_slider_margin;
          margin-top: $color_marks_slider_margin;
        }
      }
    }

    &.vertical {
      &:dir(ltr) {
        padding: 0 0 0 12px;

        slider {
          margin-left: $color_slider_margin;
          margin-right: $color_marks_slider_margin;
        }
      }

      &:dir(rtl) {
        padding: 0 12px 0 0;

        slider {
          margin-right: $color_slider_margin;
          margin-left: $color_marks_slider_margin;
        }
      }
    }
  }
}

/**
 * Progress bars
 */

progressbar {
  // FIXME: insensitive state missing and some other state should be set probably
  color: theme-color.hint(theme-color.$on-surface);
  font-size: smaller;
  font-feature-settings: "tnum";

  > trough {
    background-color: theme-color.disabled-stroke(theme-color.$on-surface);

    > progress {
      background-color: theme-color.$primary;
    }
  }

  // sizing
  &.horizontal > trough {
    min-width: 150px;

    &,
    > progress {
      min-height: 4px;
    }
  }

  &.vertical > trough {
    min-height: 80px;

    &,
    > progress {
      min-width: 4px;
    }
  }

  // progressbar.osd used for epiphany page loading progress
  &.osd {
    // min-width: 4px;
    // min-height: 4px;
    // background-color: transparent;

    > trough {
      // background-color: transparent;

      > progress {
        // background-color: $primary;
      }
    }
  }

  // makes the progress indicator disappear, when the fraction is 0
  > trough.empty > progress {
    all: unset;
  }
}

/**
 * Level Bar
 */

levelbar {
  &.horizontal {
    > trough > block {
      min-height: 4px;
    }

    &.discrete > trough > block {
      min-width: theme.$medium-size;

      &:not(:last-child) {
        margin-right: 2px;
      }
    }
  }

  &.vertical {
    > trough > block {
      min-width: 4px;
    }

    &.discrete > trough > block {
      min-height: theme.$medium-size;

      &:not(:last-child) {
        margin-bottom: 2px;
      }
    }
  }

  > trough {
  }

  > trough > block {
    &.low {
      background-color: theme-color.$warning;
    }

    &.high,
    &:not(.empty) {
      background-color: theme-color.$primary;
    }

    &.full {
      background-color: theme-color.$success;
    }

    &.empty {
      background-color: theme-color.disabled-stroke(theme-color.$on-surface);
    }
  }
}

/**
 * Print dialog
 */

window.dialog.print {
  paper {
    // padding: 0;
    // border: 1px solid divider($on-surface);
    border-radius: theme.$corner-radius;
    box-shadow: shadow.$z1;
    background-color: theme-color.$surface-z1;
    color: theme-color.$on-surface;
  }

  .dialog-action-box {
    margin: 12px;
  }
}

/**
 * Frames
 */

frame,
.frame {
  // border: 1px solid divider($on-surface);
  border-radius: theme.$corner-radius;
  box-shadow: shadow.$z1;
  background-color: theme-color.$surface-z1;
  color: theme-color.$on-surface;

  button {
    @extend %button-outlined;
  }
}

frame > label {
  margin: 4px;
}

statusbar {
  padding: 6px 10px;
  // border-top: 1px solid divider($on-surface);
}

actionbar > revealer > box {
  padding: theme.$container-padding;
  border-spacing: theme.$container-padding;
  border-top: 1px solid theme-color.divider(theme-color.$on-surface);
  // background-clip: border-box;

  button:not(.suggested-action):not(.destructive-action) {
    @extend %button-flat;
  }

  .linked:not(.vertical) > entry:not(:only-child) {
    border-radius: theme.$corner-radius theme.$corner-radius 0 0;
  }
}

scrolledwindow {
  // This is used when content is touch-dragged past boundaries.
  // draws a box on top of the content, the size changes programmatically.
  @at-root overshoot {
    &.top { @include drawing.overshoot(top); }

    &.bottom { @include drawing.overshoot(bottom); }

    &.left { @include drawing.overshoot(left); }

    &.right { @include drawing.overshoot(right); }
  }

  // Overflow indication, works similarly to the overshoot, the size if fixed tho.
  @at-root undershoot {
    // &.top { @include undershoot(top); }

    // &.bottom { @include undershoot(bottom); }

    // &.left { @include undershoot(left); }

    // &.right { @include undershoot(right); }
  }

  // the small square between two scrollbars
  @at-root junction {
    border-style: solid none none solid;
    border-width: 1px;
    border-color: theme-color.divider(theme-color.$on-surface);
    // background-color: $surface-z1;

    &:dir(rtl) {
      border-style: solid solid none none;
    }
  }
}

// vbox and hbox separators
separator {
  min-width: 1px;
  min-height: 1px;
  background-color: theme-color.divider(theme-color.$on-surface);
}

%hide_separators {
  min-width: 0;
  min-height: 0;
  background-color: transparent;
}

/**
 * Lists
 */

listview,
list {
  // background-color: $surface-z1;
  // color: $on-surface;

  > row {
    padding: 2px;

    &.expander {
      padding: 0;

      .row-header {
        padding: 2px;
      }
    }
  }

  &.separators:not(.horizontal) > row:not(:first-child) {
    border-top: 1px solid theme-color.divider(theme-color.$on-surface);
  }

  &.separators.horizontal > row:not(:first-child) {
    border-left: 1px solid theme-color.divider(theme-color.$on-surface);
  }
}

row {
  background-clip: padding-box;

  &.activatable {
    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);
    @include drawing.list-item;

    // this is for indicathing which row generated a popover
    // see https://bugzilla.gnome.org/show_bug.cgi?id=754411
    &.has-open-popup {
      background-color: theme-color.activated-overlay(theme-color.$on-surface);
    }
  }

  &:selected {
    background-color: theme-color.$selected-overlay;

    @include drawing.ink-color(theme-color.$primary, $hover-alt: true, $on: theme-color.$selected-overlay);

    &.has-open-popup {
      background-color: theme-color.activated-overlay(theme-color.$primary, $on: theme-color.$selected-overlay);
    }
  }
}

listview {
  > row {
    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface, $hover-alt: true);
    @include drawing.list-item;
  }

  &:selected {
    background-color: theme-color.$selected-overlay;

    @include drawing.ink-color(theme-color.$primary, $hover-alt: true, $on: theme-color.$selected-overlay);
  }
}

columnview {
  // move padding to child cells
  > listview > row {
    padding: 0;

    // align horizontal sizing with header buttons
    > cell {
      min-height: 24px;
      padding: 4px 6px;

      &:not(:last-child) {
        border-right: 1px solid transparent;
      }
    }
  }

  // make column separators visible when :show-column-separators is true
  &.column-separators > listview > row > cell {
    border-right-color: theme-color.divider(theme-color.$on-surface);
  }

  // shrink vertically for .data-table
  &.data-table > listview > row > cell {
    padding-top: 2px;
    padding-bottom: 2px;
  }
}

// rich lists usually containing other widgets than just labels/text
.rich-list {
  > row {
    padding: 12px;
    min-height: theme.$medium-size;

    > box {
      border-spacing: 12px;
    }
  }
}

/**
 * App Notifications
 */

.app-notification {
  @extend %toolbar-osd;
  margin: 8px;
  border-style: none;

  button {
    @extend %button-flat;

    &.text-button:not(:disabled) {
      color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary);
    }
  }
}

/**
 * Expanders
 */

expander {
  transition: all theme.$state-duration theme.$ease-out;
  min-width: 16px;
  min-height: 16px;
  padding: 4px;
  border-radius: theme.$circular-radius;
  color: theme-color.hint(theme-color.$on-surface);
  -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');

  @extend %ripple;
  @include drawing.ink-color(theme-color.$on-surface);

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }

  &:checked {
    &:dir(ltr) {
      -gtk-icon-transform: rotate(-180deg);
    }

    &:dir(rtl) {
      -gtk-icon-transform: rotate(180deg);
    }
  }
}

indent {
  min-width: 16px;
  min-height: 16px;
  padding: 4px;
}

expander-widget {
  &:focus > box > title > expander {
    box-shadow: inset 0 0 0 9999px theme-color.focus-overlay(theme-color.$on-surface);
  }

  > box > title:drop(active) > expander,
  > box > title:hover > expander {
    box-shadow: inset 0 0 0 9999px theme-color.hover-overlay(theme-color.$on-surface);
  }

  > box > title:active > expander {
    transition-duration: drawing.$ripple-active-transition-duration;
    animation: ripple theme.$ripple-duration theme.$ease-out forwards;
    background-size: 0% 0%;
    background-image: radial-gradient(circle, theme-color.pressed-overlay(theme-color.$on-surface) 10%, transparent 10%);
  }
}

/**
 * Calendar
 */

calendar {
  // border: 1px solid divider($on-surface);
  border-radius: theme.$corner-radius;
  box-shadow: shadow.$z1;
  background-color: theme-color.$surface-z1;
  color: theme-color.$on-surface;

  &:disabled {
    color: theme-color.disabled(theme-color.$on-surface);
  }

  > header {
    padding: 4px;
    border-spacing: 4px;
    border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);

    > button.image-button {
      padding: 0;
      min-width: 28px;
      min-height: 28px;
      border-radius: theme.$circular-radius;
      background-color: transparent;
      color: theme-color.hint(theme-color.$on-surface);
      @include drawing.ink-color(theme-color.$on-surface, $button-style: "flat");

      &:disabled {
        color: theme-color.disabled-hint(theme-color.$on-surface);
      }
    }
  }

  > grid {
    padding: 4px;
    border-spacing: 4px;

    > label {
      // padding: 4px;
      padding: 0;
      min-width: 28px;
      min-height: 28px;
      border-radius: theme.$circular-radius;
    }

    > label.day-name,
    > label.week-number {
      color: theme-color.hint(theme-color.$on-surface);
      font-weight: 500;
    }

    > label.day-number {
      @extend %ripple;
      @include drawing.ink-color(theme-color.$on-surface);

      &.today {
        box-shadow: inset 0 0 0 1px theme-color.hint(theme-color.$on-surface);
      }

      &.other-month {
        color: theme-color.disabled-hint(theme-color.$on-surface);
      }

      &:selected {
        background-color: theme-color.$selected-overlay;
        box-shadow: inset 0 0 0 1px transparent;
        @include drawing.ink-color(theme-color.$primary, $on: theme-color.$selected-overlay);
      }
    }
  }
}

/**
 * Dialogs
 */

window.dialog.message { // Message Dialog styling
  &.csd.background {
    min-width: 280px;
    border-radius: theme.$corner-radius; // rounded bottom border styling for csd version
    background-color: theme-color.$surface-z8;
  }

  > .titlebar {
    min-height: 24px;
    box-shadow: inset 0 1px theme-color.highlight(theme-color.$surface-z8);
    background-color: transparent;
    color: theme-color.$on-surface;

    &:backdrop {
      background-color: transparent;
      color: theme-color.hint(theme-color.$on-surface);
    }
  }

  > box.dialog-vbox.vertical {
    border-spacing: 20px;

    > box.vertical > box.horizontal {
      margin: 0 24px - 30px;
    }
  }

  label.title {
    font-weight: 500;
    font-size: pt(20px);
    letter-spacing: pt(.15px);
  }

  // Hint text
  label.title + label {
    color: theme-color.hint(theme-color.$on-surface);
  }

  list,
  .view {
    background-color: transparent;
  }

  .dialog-action-area > button {
    @extend %button-flat;

    &:not(:disabled) {
        color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary);
    }

    &.suggested-action:not(:disabled) {
      background-color: transparent;
        // color: $primary;
      // @include ink-color($primary);
    }

    &.destructive-action:not(:disabled) {
      background-color: transparent;
        color: theme-color.$error;
      @include drawing.ink-color(theme-color.$error);
    }
  }
}

.dialog-action-area {
  // margin-top: -$container-padding;
  padding: theme.$container-padding;
  border-spacing: theme.$container-padding;
}

filechooser {
  .dialog-action-box {
    border-top: 1px solid theme-color.divider(theme-color.$on-surface);
  }

  #pathbarbox {
    border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);
    // background-color: $surface-z0;

    > stack > box > button { // The new folder button
      @extend %button-flat;

      border-radius: theme.$circular-radius;
    }
  }
}

filechooserbutton > button > box {
  border-spacing: 6px;
}

filechooserbutton:drop(active) {
  // box-shadow: none;
}

/**
 * Sidebar
 */

.sidebar {
  border-style: none;

  &:not(separator) {
    @at-root %sidebar_left,
    &:dir(ltr),
    &.left,
    &.left:dir(rtl) {
      border-right: 1px solid theme-color.divider(theme-color.$on-surface);
      border-left-style: none;
    }

    @at-root %sidebar_right,
    &:dir(rtl),
    &.right {
      border-left: 1px solid theme-color.divider(theme-color.$on-surface);
      border-right-style: none;
    }
  }

  list {
    // background-color: transparent;
  }

  paned & {
    &:dir(rtl):not(:dir(ltr)),
    &:dir(ltr):not(:dir(rtl)) {
      border-style: none;
    }
  }
}

stacksidebar.sidebar {
  list {
    padding: 4px;
  }

  list.separators:not(.horizontal) > row:not(:first-child) {
    border-top-style: none;
  }

  row {
    min-height: 32px;
    padding: 0 8px - 6px;
    border-radius: theme.$corner-radius;
    color: theme-color.hint(theme-color.$on-surface);
    font-weight: 500;

    &:selected {
      background-color: theme-color.activated-overlay(theme-color.$primary);
      color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary, $on: theme-color.activated-overlay(theme-color.$primary));
    }

    + row {
      margin-top: 4px;
    }

    > label {
      padding-left: 6px;
      padding-right: 6px;
    }

    &.needs-attention > label {
      @extend %needs-attention;
    }
  }
}

separator.sidebar {
  &.selection-mode,
  .selection-mode & {
    // background-color: divider($on-surface);
  }
}

/**
 * File chooser
 */

// dim the sidebar icons, see bug #786613 for details on this oddity
row image.sidebar-icon {
  transition: color theme.$state-duration theme.$ease-out;
  color: theme-color.hint(theme-color.$on-surface);

  &:disabled {
    color: theme-color.disabled-hint(theme-color.$on-surface);
  }
}

placessidebar.sidebar {
  list {
    padding: 4px 0;

    > separator {
      margin: 4px 0;
    }
  }

  row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: 32px;
    margin: 0 4px; // Remove unwanted hard-coded vertical margins with -1px
    padding: 0;
    border-radius: theme.$corner-radius;
    color: theme-color.hint(theme-color.$on-surface);
    font-weight: 500;

    // Using margins/padding directly in the SidebarRow
    // will make the animation of the new bookmark row jump
    > revealer {
      padding: 0 8px;
    }

    &:selected {
      background-color: theme-color.activated-overlay(theme-color.$primary);
      color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary, $on: theme-color.activated-overlay(theme-color.$primary));

      image.sidebar-icon {
        color: theme-color.$primary;
      }
    }

    &:disabled {
      color: theme-color.disabled(theme-color.$on-surface);
    }

    image.sidebar-icon {
      &:dir(ltr) {
        padding-right: 8px;
      }

      &:dir(rtl) {
        padding-left: 8px;
      }
    }

    label.sidebar-label {
      &:dir(ltr) {
        padding-right: 2px;
      }

      &:dir(rtl) {
        padding-left: 2px;
      }
    }

    @at-root button.sidebar-button {
      @extend %button-flat-basic;
      @extend %button-small;
    }

    &.sidebar-placeholder-row {
      background-color: theme-color.hover-overlay(theme-color.$on-surface);
    }

    &.sidebar-new-bookmark-row {
      color: theme-color.$primary;

      image.sidebar-icon {
        color: theme-color.$primary;
      }
    }
  }
}

placesview {
  .server-list-button {
    > image {
      -gtk-icon-transform: rotate(0turn);
    }

    &:checked > image {
      -gtk-icon-transform: rotate(-0.5turn);
    }
  }

  > actionbar > revealer > box > box {
    border-spacing: theme.$container-padding;
  }

  // this selects the "connect to server" label
  > actionbar > revealer > box > box > label {
    padding-left: 8px;
    padding-right: 8px;
  }
}

/**
 * Paned
 */

paned {
  > separator {
    background-clip: content-box;
    // -gtk-icon-source: none; // defeats the ugly default handle decoration

    &.wide {
      min-width: 4px;
      min-height: 4px;
      border: 1px solid theme-color.divider(theme-color.$on-surface);
      background-color: transparent;
    }
  }

  &.horizontal > separator {
    &:not(.wide) {
      margin: 0 -4px;
      padding: 0 4px;
    }

    &.wide {
      border-style: none solid;
    }
  }

  &.vertical > separator {
    &:not(.wide) {
      margin: -4px 0;
      padding: 4px 0;
    }

    &.wide {
      border-style: solid none;
    }
  }
}

/**
 * GtkVideo
 */

video {
  background-color: black;

  image.osd {
    min-width: 64px;
    min-height: 64px;
    border-radius: 32px;
    background-color: theme-color.$scrim;
    color: theme-color.$on-scrim;
  }

  controls.osd {
    padding: 4px;
    background-image:
      linear-gradient(
        to bottom,
        transparent,
        rgba(black, .1) 30%,
        rgba(black, .2) 50%,
        rgba(black, .4)
      );
    color: theme-color.on(black);

    button {
      background-color: transparent;
      color: theme-color.hint(theme-color.on(black));
      @include drawing.ink-color(theme-color.on(black));
    }
  }
}

/**
 * GtkInfoBar
 */

infobar {
  > revealer > box {
    padding: 8px;
    border-spacing: 12px;
  }

  &.action:hover > revealer > box {
    background-image: image(theme-color.hover-overlay(theme-color.$on-surface));
  }

  &.info > revealer > box,
  &.question > revealer > box {
    border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);
    // background-color: $surface-z1;

    button {
      @extend %button-flat;

      &.text-button:not(:disabled) {
        color: theme-color.$primary;
        @include drawing.ink-color(theme-color.$primary);
      }
    }
  }

  &.warning > revealer > box {
    background-color: theme-color.$warning;
    color: theme-color.$on-warning;

    button.flat {
      color: theme-color.$on-warning;
      @include drawing.ink-color(theme-color.$on-warning);
    }

    selection {
    }

    link {
      color: theme-color.$on-warning;
    }
  }

  &.error > revealer > box {
    background-color: theme-color.$error;
    color: theme-color.$on-error;

    button.flat {
      color: theme-color.$on-error;
      @include drawing.ink-color(theme-color.$on-error);
    }

    selection {
    }

    link {
      color: theme-color.$on-error;
    }
  }

  // Remove ugly hard-coded padding
  button label {
    // margin: 0 -4px;
  }
}

/**
 * Tooltips
 */

tooltip {
  &.background {
    // background-color needs to be set this way otherwise it gets drawn twice
    // see https://bugzilla.gnome.org/show_bug.cgi?id=736155 for details.
    background-color: theme-color.$tooltip;
    color: theme-color.$on-tooltip;
  }

  min-height: 32px - 4px * 2;
  padding: 4px 8px;
  border-radius: theme.$corner-radius;

  &:not(.csd) {
    background-color: theme-color.$tooltip;
  }

  > box {
    border-spacing: 6px;
  }

  .dim-label {
    color: theme-color.hint(theme-color.$on-tooltip);
  }
}

/**
 * Color Chooser
 */

colorswatch {
  // This widget is made of two boxes one on top of the other, the lower box is colorswatch {} the other one
  // is colorswatch overlay {}, colorswatch has the programmatically set background, so most of the style is
  // applied to the overlay box.

  // base color corners rounding
  // to avoid the artifacts caused by rounded corner anti-aliasing the base color
  // sports a bigger radius.
  // nth-child is needed by the custom color strip.

  transition: theme.$transition-shadow;
  box-shadow: shadow.$z1;

  &:drop(active),
  &.activatable:hover {
    box-shadow: shadow.$z3;
  }

  &:disabled {
    opacity: .5;
    // box-shadow: none;
  }

  &.top {
    border-top-left-radius: theme.$corner-radius;
    border-top-right-radius: theme.$corner-radius;
  }

  &.bottom {
    border-bottom-left-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

  &.left,
  &:first-child:not(.top) {
    border-top-left-radius: theme.$corner-radius;
    border-bottom-left-radius: theme.$corner-radius;
  }

  &.right,
  &:last-child:not(.bottom) {
    border-top-right-radius: theme.$corner-radius;
    border-bottom-right-radius: theme.$corner-radius;
  }

  &.dark {
    color: theme-color.$on-dark;
  }

  &.light {
    color: theme-color.$on-light;
  }

  &#add-color-button {
    // border-radius: $corner-radius 0 0 $corner-radius;
    background-color: theme-color.$surface-z8;
    color: theme-color.$on-surface;

    &:only-child {
      // border-radius: $corner-radius;
    }
  }

  row:selected & {
  }

  &#editor-color-sample {
    border-radius: theme.$corner-radius;
  }
}

// colorscale popup
colorchooser .popover.osd {
  transition: theme.$transition-shadow;
  border-radius: theme.$corner-radius;
  box-shadow: shadow.$z4, inset 0 1px theme-color.highlight(theme-color.$surface-z8);
  background-color: theme-color.$surface-z8;

  &:backdrop {
    box-shadow: shadow.$z2, inset 0 1px theme-color.highlight(theme-color.$surface-z8);
  }
}

/**
 * Misc
 */

// content view (grid/list)
.content-view {
  // background-color: $surface-z0;

  &:hover {
    // -gtk-icon-filter: brightness(1.2);
  }
}

.scale-popup {
  .osd & {
    // @extend %osd;

    button.flat {
    }
  }

  // +/- buttons on GtkVolumeButton popup
  button {
  }
}

/**
 * Window Decorations
 */

window {
  &.csd {
    transition: theme.$transition-shadow;
    border-radius: theme.$corner-radius theme.$corner-radius 0 0;
    border-radius: theme.$corner-radius;
    box-shadow: shadow.$z16, 0 16px 24px 2px transparent, 0 6px 30px 5px transparent;

    &:backdrop {
      // the transparent shadow here is to enforce that the shadow extents don't
      // change when we go to backdrop, to prevent jumping windows.
      // The biggest shadow should be in the same order then in the active state
      // or the jumping will happen during the transition.
      box-shadow: shadow.$z4, 0 16px 24px 2px transparent, 0 6px 30px 5px transparent;
    }
  }

  // server-side decorations as used by mutter
  &.ssd {
    box-shadow: 0 3px 3px rgba(0, 0, 0, 0.16); // just doing borders, wm draws actual shadows
  }

  &.solid-csd {
    margin: 0;
    padding: 2px;
    border-radius: 0;
    box-shadow: none;
    box-shadow: inset 0 1px theme-color.highlight(theme-color.$titlebar);
    background-color: theme-color.$titlebar;

    &:backdrop {
      background-color: theme-color.$titlebar-backdrop;
    }
  }

  &.maximized,
  &.fullscreen,
  &.tiled,
  &.tiled-top,
  &.tiled-left,
  &.tiled-right,
  &.tiled-bottom {
    border-radius: 0;
  }
}

// catch all extend :)

%selected_items {
  background-color: theme-color.$selected-overlay;
}

.monospace {
  font-family: monospace;
}

/**
 * Touch Copy & Paste
 */

// touch selection handlebars for the Popover.osd above
cursor-handle {
  min-width: 24px;
  min-height: 24px;
  border-radius: 50%;
  background-color: theme-color.$primary;
  // -gtk-icon-source: -gtk-recolor(url("icons/cursor-handle-symbolic.svg"));

  &.top:dir(ltr),
  &.bottom:dir(rtl) {
    border-top-right-radius: 0;
    // -gtk-icon-transform: rotate(90deg);
  }

  &.bottom:dir(ltr),
  &.top:dir(rtl) {
    border-top-left-radius: 0;
    // -gtk-icon-transform: unset;
  }

  &.insertion-cursor:dir(ltr),
  &.insertion-cursor:dir(rtl) {
    margin-top: 6px;
    transform: rotate(45deg);
  }
}

shortcuts-section {
  margin: 20px;
}

.shortcuts-search-results {
  margin: 20px;
  border-spacing: 24px;
}

// shortcut window keys
shortcut {
  border-spacing: 6px;
}

shortcut > .keycap {
  min-width: 28px - 8px * 2;
  // min-height: 28px - 2px;
  min-height: 28px;
  // margin-top: 2px;
  // padding-bottom: 2px;
  padding-left: 8px;
  padding-right: 8px;

  // border: solid 1px divider($on-surface);
  // border-radius: $corner-radius + 1px;
  border-radius: theme.$corner-radius;
  // box-shadow: inset 0 -2px divider($on-surface);
  box-shadow: shadow.$z1;
  background-color: theme-color.$surface-z8;
  color: theme-color.$on-surface;
  font-size: smaller;
}

// FIXME needs to be done widget by widget, this wildcard should really die
:drop(active) {
  // caret-color: $primary;
}

// FIXME aggregate with buttons
stackswitcher > button.text-button {
  min-width: 100px;
}

stackswitcher.circular {
  border-spacing: 12px;

  // FIXME aggregate with buttons
  > button.circular {
    min-width: theme.$medium-size;
    min-height: theme.$medium-size;
    padding: 0;
  }
}

/**
 * App Icons
 */

// Outline for low res icons
.lowres-icon {
  // -gtk-icon-shadow: none;
}

// Drapshadow for large icons
.icon-dropshadow {
  // -gtk-icon-shadow: none;
}

/**
 * Emoji
 */

popover.emoji-picker > contents {
  padding: 0;

  emoji {
    min-width: 3em;
    min-height: 3em;
    // padding: 8px;
    border-radius: theme.$corner-radius;
    // font-size: larger;

    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface);
  }
}

.emoji-searchbar {
  border-bottom: 1px solid theme-color.divider(theme-color.$on-surface);

  > entry.search {
    border-image: none;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
  }
}

.emoji-toolbar {
  padding: 4px;
  border-spacing: 4px;
  border-top: 1px solid theme-color.divider(theme-color.$on-surface);

  > button.emoji-section {
    &:checked {
      background-color: theme-color.activated-overlay(theme-color.$primary);
      color: theme-color.$primary;
      @include drawing.ink-color(theme-color.$primary, $on: theme-color.activated-overlay(theme-color.$primary));
    }
  }
}

popover.emoji-completion > contents {
  padding: 8px 0;

  emoji-completion-row {
    min-height: 32px;
    padding: 0 8px;
    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface);

    > box {
      border-spacing: 8px;
    }
  }

  emoji {
    // min-width: 3em;
    // min-height: 3em;
    // padding: 8px;
    border-radius: theme.$corner-radius;

    @extend %ripple;
    @include drawing.ink-color(theme-color.$on-surface);
  }
}

popover.entry-completion > contents {
  padding: 0;

  treeview.view {
    min-height: 32px; // FIXME: should be in .cell
    padding: 8px 0;

    > .cell {
      padding: 0 4px; // FIXME: should be `0 8px`

      &:selected:hover {
        background-color: theme-color.focus-overlay(theme-color.$on-surface);
      }
    }
  }
}
